﻿using HealthcareSystem.API.Write.Application.Command.ChronicSignCommad;
using HealthcareSystem.Domain;
using MediatR;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Write.Application.CommandHandel.ChronicSignCommadHandel
{
    public class UpCsignCommadHandel : IRequestHandler<UpCsignCommad, ApiResult<int>>
    {
        private readonly IBaseRepository<ChronicSign> csignRepository;

        public UpCsignCommadHandel(IBaseRepository<ChronicSign> CsignRepository)
        {
            csignRepository = CsignRepository;
        }

        public async Task<ApiResult<int>> Handle(UpCsignCommad request, CancellationToken cancellationToken)
        {
            ApiResult<int> result=new ApiResult<int>();
            result.Code = ResultCode.Success;
            result.Message = "修改成功";

            var list= await csignRepository.GetByAsync(p => p.CSignId == request.CSignId);
            list.CSignTeam = request.CSignTeam;
            list.CSignDoctor = request.CSignDoctor;
            list.CSignBegin = request.CSignBegin;
            list.CSignEnd = request.CSignEnd;
            list.CSignManage = request.CSignManage;
            list.CSignLevel = request.CSignLevel;
            list.CSignImage = request.CSignImage;
            list.RecordId = request.RecordId;
            await csignRepository.UpdAsync(list);

            return await Task.FromResult(result);
        }
    }
}
